<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Circular shift</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Circular_shift"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Circular_shift rootpage-Circular_shift skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Circular shift</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1305433154">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<style data-mw-deduplicate="TemplateStyles:r1273380762/mw-parser-output/.tmulti">
/* start https://en.wikipedia.org/ */
.mw-parser-output .tmulti .multiimageinner{display:flex;flex-direction:column}.mw-parser-output .tmulti .trow{display:flex;flex-direction:row;clear:left;flex-wrap:wrap;width:100%;box-sizing:border-box}.mw-parser-output .tmulti .tsingle{margin:1px;float:left}.mw-parser-output .tmulti .theader{clear:both;font-weight:bold;text-align:center;align-self:center;background-color:transparent;width:100%}.mw-parser-output .tmulti .thumbcaption{background-color:transparent}.mw-parser-output .tmulti .text-align-left{text-align:left}.mw-parser-output .tmulti .text-align-right{text-align:right}.mw-parser-output .tmulti .text-align-center{text-align:center}@media all and (max-width:720px){.mw-parser-output .tmulti .thumbinner{width:100%!important;box-sizing:border-box;max-width:none!important;align-items:center}.mw-parser-output .tmulti .trow{justify-content:center}.mw-parser-output .tmulti .tsingle{float:none!important;max-width:100%!important;box-sizing:border-box;text-align:center}.mw-parser-output .tmulti .tsingle .thumbcaption{text-align:left}.mw-parser-output .tmulti .trow>.thumbcaption{text-align:center}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .tmulti .multiimageinner span:not(.skin-invert-image):not(.skin-invert):not(.bg-transparent) img{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .tmulti .multiimageinner span:not(.skin-invert-image):not(.skin-invert):not(.bg-transparent) img{background-color:white}}
/* end https://en.wikipedia.org/ */
</style><div class="thumb tmulti tright"><div class="thumbinner multiimageinner" style="width:392px;max-width:392px"><div class="trow"><div class="tsingle" style="width:194px;max-width:194px"><div class="thumbimage" style="height:168px;overflow:hidden"><span typeof="mw:File"></span></div></div><div class="tsingle" style="width:194px;max-width:194px"><div class="thumbimage" style="height:168px;overflow:hidden"><span typeof="mw:File"></span></div></div></div><div class="trow" style="display:flex"><div class="thumbcaption"><a href="Permutation_matrix" title="Permutation matrix">Matrices</a> of 8-element circular shifts to the left and right</div></div></div></div>
<p>In <a href="Combinatorics" title="Combinatorics">combinatorial</a> <a href="Mathematics" title="Mathematics">mathematics</a>, a <b>circular shift</b> is the operation of rearranging the entries in a <a href="Tuple" title="Tuple">tuple</a>, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation. A circular shift is a special kind of <a href="Cyclic_permutation" title="Cyclic permutation">cyclic permutation</a>, which in turn is a special kind of <a href="Permutation" title="Permutation">permutation</a>. Formally, a circular shift is a <a href="Permutation" title="Permutation">permutation</a> σ of the <i>n</i> entries in the tuple such that either
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \sigma (i)\equiv (i+1)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>σ<!-- σ --></mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo stretchy="false">)</mo>
<mo>≡<!-- ≡ --></mo>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>+</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \sigma (i)\equiv (i+1)}</annotation>
</semantics>
</math></span><img src="./f3d1fbdd6372c22119032adf0398c6c172f8e739.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.655ex; height:2.843ex;" alt="{\displaystyle \sigma (i)\equiv (i+1)}" loading="lazy"></span> <a href="Modular_arithmetic" title="Modular arithmetic">modulo</a> <i>n</i>, for all entries <i>i</i> = 1, ..., <i>n</i></dd></dl>
<p>or
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \sigma (i)\equiv (i-1)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>σ<!-- σ --></mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo stretchy="false">)</mo>
<mo>≡<!-- ≡ --></mo>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \sigma (i)\equiv (i-1)}</annotation>
</semantics>
</math></span><img src="./a65139cfef5b7267f19ee66727ff676f37308ea4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.655ex; height:2.843ex;" alt="{\displaystyle \sigma (i)\equiv (i-1)}" loading="lazy"></span> <a href="Modular_arithmetic" title="Modular arithmetic">modulo</a> <i>n</i>, for all entries <i>i</i> = 1, ..., <i>n</i>.</dd></dl>
<p>The result of repeatedly applying circular shifts to a given tuple are also called the <b>circular shifts</b> of the tuple.
</p><p>For example, repeatedly applying circular shifts to the four-tuple (<i>a</i>, <i>b</i>, <i>c</i>, <i>d</i>) successively gives
</p>
<ul><li>(<i>d</i>, <i>a</i>, <i>b</i>, <i>c</i>),</li>
<li>(<i>c</i>, <i>d</i>, <i>a</i>, <i>b</i>),</li>
<li>(<i>b</i>, <i>c</i>, <i>d</i>, <i>a</i>),</li>
<li>(<i>a</i>, <i>b</i>, <i>c</i>, <i>d</i>) (the original four-tuple),</li></ul>
<p>and then the sequence repeats; this four-tuple therefore has four distinct circular shifts. However, not all <i>n</i>-tuples have <i>n</i> distinct circular shifts. For instance, the 4-tuple (<i>a</i>, <i>b</i>, <i>a</i>, <i>b</i>) only has 2 distinct circular shifts. The number of distinct circular shifts of an <i>n</i>-tuple is <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {n}{k}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mi>n</mi>
<mi>k</mi>
</mfrac>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\frac {n}{k}}}</annotation>
</semantics>
</math></span><img src="./a3de84bab054ffbe095b1f1d9422876cc3a1d7ae.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.005ex; width:2.231ex; height:4.843ex;" alt="{\displaystyle {\frac {n}{k}}}" loading="lazy"></span>, where <span class="texhtml mvar" style="font-style:italic;">k</span> is a <a href="Divisor" title="Divisor">divisor</a> of <span class="texhtml mvar" style="font-style:italic;">n</span>, indicating the maximal number of repeats over all subpatterns.
</p><p>In <a href="Computer_programming" title="Computer programming">computer programming</a>, a <a href="Bitwise_rotation" class="mw-redirect" title="Bitwise rotation">bitwise rotation</a>, also known as a circular shift, is a bitwise operation that shifts all bits of its operand. Unlike an <a href="Arithmetic_shift" title="Arithmetic shift">arithmetic shift</a>, a circular shift does not preserve a number's sign bit or distinguish a <a href="Floating-point_number" class="mw-redirect" title="Floating-point number">floating-point number</a>'s <a href="Exponent" class="mw-redirect" title="Exponent">exponent</a> from its <a href="Significand" title="Significand">significand</a>. Unlike a <a href="Logical_shift" title="Logical shift">logical shift</a>, the vacant bit positions are not filled in with zeros but are filled in with the bits that are shifted out of the sequence.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Implementing_circular_shifts">Implementing circular shifts</h2></div>
<p>Circular shifts are used often in <a href="Cryptography" title="Cryptography">cryptography</a> in order to permute bit sequences. Unfortunately, many programming languages, including <a href="C_(programming_language)" title="C (programming language)">C</a>, do not have operators or standard functions for circular shifting, even though virtually all <a href="Processor_(computing)" title="Processor (computing)">processors</a> have <a href="Bitwise_operation" title="Bitwise operation">bitwise operation</a> instructions for it (e.g. <a href="Intel_x86" class="mw-redirect" title="Intel x86">Intel x86</a> has ROL and ROR).
However, some compilers may provide access to the processor instructions by means of <a href="Intrinsic_function" title="Intrinsic function">intrinsic functions</a>. In addition, some constructs in standard <a href="ANSI_C" title="ANSI C">ANSI C</a> code may be optimized by a compiler to the "rotate" assembly language instruction on CPUs that have such an instruction. Most C compilers recognize the following idiom, and compile it to a single 32-bit rotate instruction.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="cm">/*</span>
<span class="cm"> * Shift operations in C are only defined for shift values which are</span>
<span class="cm"> * not negative and smaller than sizeof(value) * CHAR_BIT.</span>
<span class="cm"> * The mask, used with bitwise-and (&), prevents undefined behaviour</span>
<span class="cm"> * when the shift count is 0 or >= the width of unsigned int.</span>
<span class="cm"> */</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><stdint.h></span><span class="c1"> // for uint32_t, to get 32-bit-wide rotates, regardless of the size of int.</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><limits.h></span><span class="c1"> // for CHAR_BIT</span>
<span class="kt">uint32_t</span><span class="w"> </span><span class="nf">rotl32</span><span class="w"> </span><span class="p">(</span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">count</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">mask</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">CHAR_BIT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
<span class="w"> </span><span class="n">count</span><span class="w"> </span><span class="o">&=</span><span class="w"> </span><span class="n">mask</span><span class="p">;</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">value</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">count</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="p">(</span><span class="n">value</span><span class="w"> </span><span class="o">>></span><span class="w"> </span><span class="p">(</span><span class="o">-</span><span class="n">count</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="n">mask</span><span class="p">));</span>
<span class="p">}</span>
<span class="kt">uint32_t</span><span class="w"> </span><span class="nf">rotr32</span><span class="w"> </span><span class="p">(</span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">count</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">mask</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">CHAR_BIT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
<span class="w"> </span><span class="n">count</span><span class="w"> </span><span class="o">&=</span><span class="w"> </span><span class="n">mask</span><span class="p">;</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">value</span><span class="w"> </span><span class="o">>></span><span class="w"> </span><span class="n">count</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="p">(</span><span class="n">value</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="p">(</span><span class="o">-</span><span class="n">count</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="n">mask</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>
<p>This safe and compiler-friendly implementation was developed by <a href="John_Regehr" title="John Regehr">John Regehr</a>,<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> and further polished by Peter Cordes.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p><p>A simpler version is often seen when the <code>count</code> is limited to the range of 1 to 31 bits:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">uint32_t</span><span class="w"> </span><span class="nf">rotl32</span><span class="w"> </span><span class="p">(</span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">count</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">value</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">count</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="p">(</span><span class="n">value</span><span class="w"> </span><span class="o">>></span><span class="w"> </span><span class="p">(</span><span class="mi">32</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">count</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>
<p>This version is dangerous because if the <code>count</code> is 0 or 32, it asks for a 32-bit shift, which is <a href="Undefined_behaviour" class="mw-redirect" title="Undefined behaviour">undefined behaviour</a> in the C language standard. However, it tends to work anyway, because most microprocessors implement <code>value >> 32</code> as either a 32-bit shift (producing 0) or a 0-bit shift (producing the original <code>value</code>), and either one produces the correct result in this application.
</p>
<div class="mw-heading mw-heading2"><h2 id="Example">Example</h2></div>
<p>If the bit sequence 0001 0111 were subjected to a circular shift of one bit position... (see images below)
</p>
<table>
<tbody><tr>
<td>
<ul><li>to the left would yield: 0010 1110</li></ul>
</td>
<td>
<ul><li>to the right would yield: 1000 1011.</li></ul>
</td></tr></tbody></table>
<p>If the bit sequence 1001 0110 were subjected to the following operations:
</p>
<table style="float:left;">
<tbody><tr>
<td>left circular shift by 1 position:
</td>
<td>0010 1101
</td></tr>
<tr>
<td>left circular shift by 2 positions:
</td>
<td>0101 1010
</td></tr>
<tr>
<td>left circular shift by 3 positions:
</td>
<td>1011 0100
</td></tr>
<tr>
<td>left circular shift by 4 positions:
</td>
<td>0110 1001
</td></tr>
<tr>
<td>left circular shift by 5 positions:
</td>
<td>1101 0010
</td></tr>
<tr>
<td>left circular shift by 6 positions:
</td>
<td>1010 0101
</td></tr>
<tr>
<td>left circular shift by 7 positions:
</td>
<td>0100 1011
</td></tr>
<tr>
<td>left circular shift by 8 positions:
</td>
<td>1001 0110
</td></tr></tbody></table>
<table style="float:left;">
<tbody><tr>
<td>right circular shift by 1 position:
</td>
<td>0100 1011
</td></tr>
<tr>
<td>right circular shift by 2 positions:
</td>
<td>1010 0101
</td></tr>
<tr>
<td>right circular shift by 3 positions:
</td>
<td>1101 0010
</td></tr>
<tr>
<td>right circular shift by 4 positions:
</td>
<td>0110 1001
</td></tr>
<tr>
<td>right circular shift by 5 positions:
</td>
<td>1011 0100
</td></tr>
<tr>
<td>right circular shift by 6 positions:
</td>
<td>0101 1010
</td></tr>
<tr>
<td>right circular shift by 7 positions:
</td>
<td>0010 1101
</td></tr>
<tr>
<td>right circular shift by 8 positions:
</td>
<td>1001 0110
</td></tr></tbody></table>
<div style="clear:both;" class=""></div>
<div class="mw-heading mw-heading2"><h2 id="Applications">Applications</h2></div>
<p><a href="Cyclic_code" title="Cyclic code">Cyclic codes</a> are a kind of <a href="Block_code" title="Block code">block code</a> with the property that the circular shift of a codeword will always yield another codeword. This motivates the following general definition: For a <a href="String_(computer_science)" title="String (computer science)">string</a> <i>s</i> over an alphabet <i>Σ</i>, let <i>shift</i>(<i>s</i>) denote the <a href="Set_(mathematics)" title="Set (mathematics)">set</a> of circular shifts of <i>s</i>,
and for a set <i>L</i> of strings, let <i>shift</i>(<i>L</i>) denote the set of all circular shifts of strings in <i>L</i>. If <i>L</i> is a cyclic code, then <i>shift</i>(<i>L</i>) ⊆ <i>L</i>; this is a necessary condition for <i>L</i> being a <a href="Cyclic_language" title="Cyclic language">cyclic language</a>. The operation <i>shift</i>(<i>L</i>) has been studied in <a href="Formal_language_theory" class="mw-redirect" title="Formal language theory">formal language theory</a>. For instance, if <i>L</i> is a <a href="Context-free_language" title="Context-free language">context-free language</a>, then <i>shift</i>(<i>L</i>) is again context-free.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> Also, if <i>L</i> is described by a <a href="Regular_expression" title="Regular expression">regular expression</a> of length <i>n</i>, there is a regular expression of length <a href="Big_O_notation" title="Big O notation">O</a>(<i>n</i><sup>3</sup>) describing <i>shift</i>(<i>L</i>).<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Barrel_shifter" title="Barrel shifter">Barrel shifter</a></li>
<li><a href="Circulant" class="mw-redirect" title="Circulant">Circulant</a></li>
<li><a href="Lyndon_word" title="Lyndon word">Lyndon word</a></li>
<li><a href="Necklace_(combinatorics)" title="Necklace (combinatorics)">Necklace</a> — an object like a <a href="Tuple" title="Tuple">tuple</a> but for which circular shifts are considered equivalent.</li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text">
<a rel="nofollow" class="external text" href="https://gcc.gnu.org/ml/gcc-patches/2007-11/msg01112.html">GCC: "Optimize common rotate constructs"</a></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text">
<a rel="nofollow" class="external text" href="http://www.mail-archive.com/llvm-commits@cs.uiuc.edu/msg17216.html">"Cleanups in ROTL/ROTR DAG combiner code"</a> mentions that this code supports the "rotate" instruction in the CellSPU</span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://blog.regehr.org/archives/1063">Safe, Efficient, and Portable Rotate in C/C++</a></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://stackoverflow.com/a/776523/224132">Stackoverflow: Best practices for rotates in C/C++</a></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://stackoverflow.com/a/31488147/224132">Near constant time rotate that does not violate the standards</a></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text">T. Oshiba, "Closure property of the family of context-free languages under the cyclic shift operation", Transactions of IECE, <b>55D</b>:119–122, 1972.</span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text">A. N. Maslov, "Cyclic shift operation for languages", Problems of Information Transmission <b>9</b>:333–338, 1973.</span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFGruberHolzer2009" class="citation journal cs1">Gruber, Hermann; Holzer, Markus (2009). <a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.tcs.2009.04.009">"Language operations with regular expressions of polynomial size"</a>. <i>Theoretical Computer Science</i>. <b>410</b> (35): <span class="nowrap">3281–</span>3289. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.tcs.2009.04.009">10.1016/j.tcs.2009.04.009</a></span>. <a href="Zbl_(identifier)" class="mw-redirect" title="Zbl (identifier)">Zbl</a> <a rel="nofollow" class="external text" href="https://zbmath.org/?format=complete&q=an:1176.68105">1176.68105</a>.</cite>.</span>
</li>
</ol></div></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2024-11-02" href="https://en.wikipedia.org/wiki/?title=Circular_shift&oldid=1254892127">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>